********************************************************************************
*
**#	Fig 6.A: Effects by Age: Conviction
*
********************************************************************************

use "${DATA}/data_DV.dta", clear

eststo clear 

cap drop age_cat  
gen 	age_cat = . 
replace age_cat = 1 if inrange(age,17,25) 
replace age_cat = 2 if inrange(age,25,35) 
replace age_cat = 3 if inrange(age,35,50) 
replace age_cat = 4 if age >= 50 

cap drop perc_* 
cap drop a_* 
tab age_cat, gen(a_)
	label variable a_1  "17-24"	
	label variable a_2  "25-34"
	label variable a_3  "35-49"
	label variable a_4  "50+" 

forval j = 1/4 {	
			
	eststo dd_age_`j': ///
	reghdfe guilty_case dv_did dv_case dv_judge $cntrls if a_`j'==1, $hdfe_opts 
	
		/* calculating the percentage effect compared to mean */	
		
		estadd ysumm 
		
		gen perc_`j' = string(abs(round((_b[dv_did]/e(ymean))*100),0.1))
		
		replace perc_`j' = "("+perc_`j'+"%)" 
}

* 	N in each category:

forval h = 1/4 {	
	sum  age if age_cat == `h'	
	local obs_`h': di r(N)	
	dis `obs_`h''	
}	

# d ; 

/* graph label options */

local opt 
		"mlcolor(black) 
		mfcolor(gray)
		mlabel 
		mlabcolor(black)
		mlabposition(12) 
		mlabgap(*2) 
		mlcolor(black) 
		msize(medsmall)"
		;
	
coefplot
	(dd_age_1, mlabel(perc_1) `opt' rename(dv_did ="{bf:17-24}   (N=`obs_1')"))
	(dd_age_2, mlabel(perc_2) `opt' rename(dv_did ="{bf:25-34}   (N=`obs_2')"))
	(dd_age_3, mlabel(perc_3) `opt' rename(dv_did ="{bf:35-49}   (N=`obs_3')"))
	(dd_age_4, mlabel(perc_4) `opt' rename(dv_did ="{bf:50+}     (N=`obs_4')"))
	,
	keep(dv_did) 
	xline(
		0, lpattern(dot) lc(black))
	xtitle("")
	xscale(
		range(-0.35 0.35))
	xlab(
		-0.3 "-0.3pp" -0.2 "-0.2pp" -0.1 "-0.1pp" 0 "0" 
	   0.1 "0.1pp" 0.2 "0.2pp" 0.3 "0.3pp",labsize(medsmall)) 
	grid(none)
	title(
		"{bf:Conviction}"
		, size(medium) justification(left) margin(b+1 t+2) bexpand) 
	ciopts(
		recast(rcap) lpattern(dash) lwidth(thin) lcolor(black) )  
	nokey 
	plotlabels(black)
	offset(0) 
	name(age_coef, replace); 		

# d cr


********************************************************************************
*
**# Fig 6.B: Recidivism by Age: Any Reoffend
*
********************************************************************************

eststo clear 

cap drop perc_* 

forval j = 1/4 {			
	eststo dd_age_`j': ///
	reghdfe recid_3 dv_did dv_case dv_judge $cntrls if a_`j' == 1, $hdfe_opts 
	
	/* calculating the percentage effect compared to mean */	
		
		estadd ysumm 
		
		gen perc_`j' = string(abs(round((_b[dv_did]/e(ymean))*100),0.1))
		
		replace perc_`j' = "("+perc_`j'+"%)" 
}

* 	N in each category:

forval h = 1/4 { 
	sum  age if age_cat == `h'  
	local obs_`h': di r(N)  
	dis `obs_`h'' 
} 

# d ;

/* graph label options */

local opt 
	"mlcolor(black) mfcolor(gray) mlabel mlabcolor(black) mlabposition(12) mlabgap(*2) mlcolor(black) msize(medsmall)" ;
	 
coefplot
	(dd_age_1, mlabel(perc_1) `opt' rename(dv_did ="{bf:17-24}   (N=`obs_1')"))
	(dd_age_2, mlabel(perc_2) `opt' rename(dv_did ="{bf:25-34}   (N=`obs_2')"))
	(dd_age_3, mlabel(perc_3) `opt' rename(dv_did ="{bf:35-49}   (N=`obs_3')"))
	(dd_age_4, mlabel(perc_4) `opt' rename(dv_did ="{bf:50+}     (N=`obs_4')"))
	,
	keep(dv_did) 
	xline(
		0, lpattern(dot) lc(black))
	xtitle(
		"")
		xscale(
		range(-0.35 0.35))
	xlab(
		-0.3 "-0.3pp" -0.2 "-0.2pp" -0.1 "-0.1pp" 0 "0" 
	   0.1 "0.1pp" 0.2 "0.2pp" 0.3 "0.3pp",labsize(medsmall)) 
		grid(none)
	title(
		"{bf:Any Charge <3 yrs}"
		, size(medium) justification(left) margin(b+1 t+2) bexpand) 
	ciopts(
		recast(rcap) lpattern(dash) lwidth(thin) lcolor(black))  
	nokey 
	plotlabels(black)
	offset(0)		
	name(age_recid, replace); 
	
# d cr 

/* Combine 6.A & 6.B */
	
graph 	combine age_coef age_recid, ///
		col(1) imargin(zero) xcommon ycommon xsize(24) ysize(16) 

graph save "${OUTPUT}/fig6.gph", replace 

********************************************************************************
*   End of File
********************************************************************************
